<template>
	<view class="container">
		<view class="tabbar">
			<image class="tabbar-image" src="http://139.159.229.212:8889/index/fujiajia/tabbar.png" mode=""></image>
			<view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index" @click="selectTab(index)"
				:class="{ 'active': selectedIndex === index || (selectIndex === index) }">
				<image :src="selectedIndex === index || (selectIndex === index) ? item.active_icon : item.icon" mode="">
				</image>
				<view class="tabbar-text">
					{{item.title}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			selectIndex: {
				type: Number,
				default: -1
			}
		},
		data() {
			return {
				selectedIndex: null, // 初始选中第一个 tab
				tabbarList: [{
						icon: "http://139.159.229.212:8889/index/fujiajia/形状.png",
						active_icon: "http://139.159.229.212:8889/index/fujiajia/编组.png",
						title: "首页",
						url: "/newsPage/index/index"
					},
					{
						icon: "http://139.159.229.212:8889/index/fujiajia/编组 23.png",
						active_icon: "http://139.159.229.212:8889/index/fujiajia/grid_a.png",
						title: "分类",
						url: "/newsPage/grid/grid"
					},
					{
						icon: "http://139.159.229.212:8889/index/fujiajia/编组 24.png",
						active_icon: "http://139.159.229.212:8889/index/fujiajia/user_a.png",
						title: "我的",
						url: "/newsPage/mine/mine"
					}
				]
			};
		},
		methods: {
			selectTab(index) {
				this.selectedIndex = index;
				if (this.tabbarList[index].url) {
					uni.navigateTo({
						url: this.tabbarList[index].url
					});
				}
			}
		}
	};
</script>

<style lang="less" scoped>
	.tabbar {
		position: fixed;
		height: 178rpx;
		width: 750rpx;
		z-index: 999;
		bottom: 0%;
		left: 0%;
		display: flex;
		align-items: center;

		.tabbar-image {
			position: absolute;
			width: 100%;
			height: 100%;
			left: 0%;
			bottom: 0%;
			z-index: -1;
		}

		.tabbar-item {
			z-index: 16;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			width: 33.33%;
			float: left;
			padding: 10rpx 0;
			color: #333;
			text-decoration: none;

			image {
				width: 40rpx;
				height: 40rpx;
				margin-bottom: 5rpx;
			}

			.tabbar-text {
				font-size: 24rpx;
			}
		}

		.active {
			.tabbar-text {
				color: #ff9b45;
			}
		}
	}
</style>